/**
 * 
 */
package no.ntnu.item.arctis.runtime;

import java.util.HashSet;
import java.util.Set;

import no.ntnu.item.arctis.runtime.Scheduler.InputQueue;

public abstract class IStateMachine {

	public static final int SAVE_SIGNAL = 0;
	public static final int CONSUME_SIGNAL = 1;
	public static final int DISCARD_SIGNAL = 2;
	public static final int EXCEPTION = 3;
	public static final int TRIGGER_UNKNOWN = 4;
	public static final int TERMINATE_MACHINE = 5;
	public static final int BLOCKING_CHOICE = 6;
	
	protected void registerAlias(String alias, String sessionID) {
	}
	
//	protected void deregister(String alias) {
//		if(alias==null) Logger.getLogger().applicationError("Provided alias is null", null);
//		_alias.remove(alias);
//	}
	
//    public String getAllAlias(String sessionID) {
//    	String a = "";
//    	for(Object o: _alias.entrySet()) {
//    		Entry e = (Entry) o;
//    		if(e.getValue().equals(sessionID)) {
//    			a = a + e.getKey() + " ";
//    		}
//    	}
//    	return a;
//    }
	
//	public findSession(String alias) {
//		return (String) _alias.get(alias);
//	}
	
	public int getSessionCount() {
		return 0;
	}
	

	public abstract int fireInitial();

	public abstract int fire(Object sender, Object receiver, String signalId, Object data);

	public abstract int fireTimer(String timerId);

	//public abstract void setProperty(String id, Object property);
	
	private InputQueue queue;
	
	public IStateMachine(String sessionID, String parentSessionID) {
		this.queue = new InputQueue(this);
		this.sessionID = sessionID;
		this.parentSessionID = parentSessionID;
	}
	
	InputQueue getInputQueue() {
		return queue;
	}
	
	protected String parentSessionID;
	protected String sessionID;
	protected String sessionAlias;
	
	protected int _state;
	
	String getSessionId() {
		return sessionID;
	}
	
	protected Set<String> childSessions = new HashSet<String>();
	
}